package ren.kane.asdppp.transaction.source;

import ren.kane.asdppp.transaction.Transaction;
import ren.kane.asdppp.transaction.change.classification.ChangeHourlyTransaction;
import ren.kane.asdppp.transaction.cost.TimeCardTransaction;
import ren.kane.asdppp.transaction.employee.AddHourlyEmployee;
import ren.kane.asdppp.transaction.employee.AddSalariedEmployee;

import java.time.LocalDate;

/**
 * @author renrk(1275) on 2019-04-21 9:58 PM
 **/
public class TextParserTransactionSource extends TransactionSource {

    String[] command = new String[]{};

    public TextParserTransactionSource() {
    }

    public TextParserTransactionSource(String[] command) {
        this.command = command;
    }

    @Override
    protected Transaction getTransaction() {
        switch (command[0]) {
            case "AddMonthlyEmployee":
                return new AddSalariedEmployee(Integer.parseInt(command[1]), command[2], command[3], Double.parseDouble(command[4]));
            case "AddHourlyEmployee":
                return new AddHourlyEmployee(Integer.parseInt(command[1]), command[2], command[3], Double.parseDouble(command[4]));
            case "AddTimeCard":
                return new TimeCardTransaction(LocalDate.parse(command[2]), Double.parseDouble(command[3]), Integer.parseInt(command[1]));
            case "ChangeToHourlyEmployee":
                return new ChangeHourlyTransaction(Integer.parseInt(command[1]), Double.parseDouble(command[2]));
            default:
                return null;
        }
    }
}